package com.unionpay.mpds.model;

// default package

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;

/**
 * Permit entity. @author MyEclipse Persistence Tools
 */
@Entity
@Table(name = "T_PERMIT", uniqueConstraints = @UniqueConstraint(columnNames = "PERMIT_INDEX"))
public class Permit implements java.io.Serializable {

	// Fields

	/**
	 * 
	 */
	private static final long serialVersionUID = -6954575479152820793L;
	private Role role;
	private Menu menu;
	private String menuFlag;
	private String permitIndex;

	// Constructors

	/** default constructor */
	public Permit() {
	}

	/** full constructor */
	public Permit(Role role, Menu menu, String menuFlag,
			String permitIndex) {
		this.role = role;
		this.menu = menu;
		this.menuFlag = menuFlag;
		this.permitIndex = permitIndex;
	}

	// Property accessors

	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="ROLE_ID", nullable=false)
	public Role getRole() {
		return this.role;
	}

	public void setRole(Role role) {
		this.role = role;
	}

	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="MENU_ID", nullable=false)
	public Menu getMenu() {
		return this.menu;
	}

	public void setMenu(Menu menu) {
		this.menu = menu;
	}

	@Column(name = "MENU_FLAG", nullable = false, length = 1)
	public String getMenuFlag() {
		return this.menuFlag;
	}

	public void setMenuFlag(String menuFlag) {
		this.menuFlag = menuFlag;
	}

	@Id
	@Column(name = "PERMIT_INDEX", unique = true, nullable = false, length = 7)
	public String getPermitIndex() {
		return this.permitIndex;
	}

	public void setPermitIndex(String permitIndex) {
		this.permitIndex = permitIndex;
	}

	public boolean equals(Object other) {
		if ((this == other))
			return true;
		if ((other == null))
			return false;
		if (!(other instanceof Permit))
			return false;
		Permit castOther = (Permit) other;

		return ((this.getRole() == castOther.getRole()) || (this
				.getRole() != null && castOther.getRole() != null && this
				.getRole().equals(castOther.getRole())))
				&& ((this.getMenu() == castOther.getMenu()) || (this
						.getMenu() != null && castOther.getMenu() != null && this
						.getMenu().equals(castOther.getMenu())))
				&& ((this.getMenuFlag() == castOther.getMenuFlag()) || (this
						.getMenuFlag() != null
						&& castOther.getMenuFlag() != null && this
						.getMenuFlag().equals(castOther.getMenuFlag())))
				&& ((this.getPermitIndex() == castOther.getPermitIndex()) || (this
						.getPermitIndex() != null
						&& castOther.getPermitIndex() != null && this
						.getPermitIndex().equals(castOther.getPermitIndex())));
	}

	public int hashCode() {
		int result = 17;

		result = 37 * result
				+ (getRole() == null ? 0 : this.getRole().hashCode());
		result = 37 * result
				+ (getMenu() == null ? 0 : this.getMenu().hashCode());
		result = 37 * result
				+ (getMenuFlag() == null ? 0 : this.getMenuFlag().hashCode());
		result = 37
				* result
				+ (getPermitIndex() == null ? 0 : this.getPermitIndex()
						.hashCode());
		return result;
	}

}